package paquete;

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
	 
	public class EnvioCorreo
	{
		public static void sendEmail(Session session, String toEmail, String subject, String body){
	        try
	        {
	          MimeMessage msg = new MimeMessage(session);
	          //set message headers
	          msg.addHeader("Content-type", "text/HTML; charset=UTF-8");
	          msg.addHeader("format", "flowed");
	          msg.addHeader("Content-Transfer-Encoding", "8bit");
	 
	          msg.setFrom(new InternetAddress("biblioalepoo@gmail.com", "Biblioteca Alejandrina"));
	 
	          msg.setReplyTo(InternetAddress.parse("biblioalepoo@gmail.com", false));
	 
	          msg.setSubject(subject, "UTF-8");
	 
	          msg.setContent(body, "text/html; charset=utf-8");
	 
	          msg.setSentDate(new Date());
	 
	          msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toEmail, false));
	          System.out.println("Correo listo: enviando...");
	          Transport.send(msg); 
	 
	          System.out.println("¡Correo enviado a " + toEmail + " satisfactoriamente!");
	        }
	        catch (Exception e) {
	          e.printStackTrace();
	        }
	    }
	}

